var $table = $("#costTab");

$(function () {
	//时间控件
	$.initDateScope('startTime','endTime',false);
    initTable();
    //条件查询
    $("#queryOrderBtn").click(function () {
        $table.bootstrapTable('refresh');	 //使用post提交
    });
   
});

function initTable() {
    $table.bootstrapTable({
        dataType: "json",
        showColumns: true, 
        pagination: true, //分页
        striped: true,
        cache: false,	//是否使用缓存，默认是true
        pageSize: 10,
        pageNumber: 1,
        queryParamsType: 'limit',
        smartDisplay: true,
        sidePagination: "server",
        method: "post",	//使用post提交
        url: '../costsharing/getCostSharingInfoByPage.htm',
        contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
        columns: [
            {
                title: "序号",
                align: 'center',
                formatter:function(value,row,index){
                    return index + 1;
                }
            },
            {
                title: "订单编号",
                field: "orderNum",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "司机用户名",
                field: "driver.driverName",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "司机真实姓名",
                field: "driver.driverRealName",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "司机编号",
                field: "driverNum",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "公司名称",
                field: "company.comnumName",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "公司编号",
                field: "companyNum",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "总费用(元)",
                field: "webCarriage",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "平台分成费用(元)",
                field: "platFormCostSharing",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "公司分成费用(元)",
                field: "companyCostSharing",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "司机分成费用(元)",
                field: "driverCostSharing",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "类型",
                field: "costSharingType",
                align: 'center',
                formatter: function(value, row, index){
                    var orderManifestState = "-";
                    if(row.costSharingType == 1){
                        orderManifestState = '<span style="color:#ed5565;">短运</span>';
                    }else if(row.costSharingType == 2){
                        orderManifestState ='<span style="color:green;">长运</span>';
                    }
                    return orderManifestState;
                }
            },
            {
            	title: "分成时间",
                field: "insTime",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "支付订单号",
                field: "paymentOrderNo",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "分账响应信息",
                field: "retInfo",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "操作",
                align: 'center',
                formatter: function (value, row, index) {
                    var d = '';
                    var e = '';
                    if(row.retCode == "S0000S"){
                    	e = '<button class="btn btn-xs btn-info" type="button" onclick="accdetails(\'' + row.paymentOrderNo + '\')">详情 </button> ';
                    }
                    if (row.retCode == "BP001F"||row.retCode == "BP004F"||row.retCode == "BP005F"||row.retCode == "S0000F"){
                    	//if(row.data!=""||row.data!=undefined||row.data!=null){
                    		 d = '<button class="btn btn-xs btn-warning" type="button" onclick="accounts(\'' + row.paymentOrderNo + '\',\'' + JSON.parse(row.data) + '\')">分账 </button> ';
                    		// return e + d;
                    	//}
                    }
                    return e+d;
                }
            }
            
        ],
        onClickRow: function(row, $element, field){	//当点击某一行时，该行背景颜色改变
        	var trObj = $($element[0]);
        	var dataIndex = trObj.attr('data-index');
        	$("tr[data-index != '" + dataIndex + "']").removeAttr('style');
        	trObj.attr('style', 'background: #B4EEB4');
        }
    });
}
function accounts(paymentOrderNo, dataJsonStr) {
    layer.confirm('你确定要再次分账么', {
        btn: ['确定', '取消'] //按钮
    }, function () {
   /* 	var dataStr = JSON.stringify(dataJsonStr);
    	console.log(dataStr);*/
        $.ajax({
            url: "../costsharing/againRequestCutPay.htm",
            cache: false,
            type: "post",
            dataType: "json",
            data: {'paymentOrderNo': paymentOrderNo,'dataJsonStr':dataJsonStr},
            success: function (result) {
              if (result.status == 0) {
                   layer.msg(result.message, {icon: 1});
                    $table.bootstrapTable('refresh', {url: '../costsharing/getCostSharingInfoByPage.htm'});
                   return;
                }
               layer.msg(result.message, {icon: 2});
          }
        });
    }, function () {
    });
}
function accdetails(paymentOrderNo){
	var index = layer.open({
	      type: 2,
	      title: '分账详情',
	      shadeClose: false,
	      shade: false,
//	      maxmin: true, //开启最大化最小化按钮
	      area: ['1300px', '800px'],
	      content: '../costsharing/cut_pay_info.htm?paymentOrderNo='+paymentOrderNo,
		});
layer.full(index);
}


